package com.zhao.practice;

import com.zhao.utils.ElasticsearchUtils;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;

import java.net.UnknownHostException;

@Slf4j
public class QueryText {
    public static void main(String[] args) throws UnknownHostException {
        TransportClient transportClient = ElasticsearchUtils.getTransportClient();
        SearchRequestBuilder requestBuilder = transportClient.prepareSearch("ems").setTypes("emp");
        MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
        SearchResponse searchResponse = requestBuilder.setQuery(matchAllQueryBuilder).get();
        SearchHit[] hits = searchResponse.getHits().getHits();
        for (SearchHit hit : hits) {
            log.info("查询到数据：{}", hit.getSourceAsString());
        }
    }
}
